package com.ruoyi.background.service.impl;

import com.ruoyi.background.domain.AppActivityShowRead;
import com.ruoyi.background.mapper.AppActivityShowReadMapper;
import com.ruoyi.background.service.IAppActivityShowReadService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 活动风采浏览记录Service业务层处理
 *
 * @author susu
 * @date 2024-08-26
 */
@Service
public class AppActivityShowReadServiceImpl implements IAppActivityShowReadService {
    @Autowired
    private AppActivityShowReadMapper appActivityShowReadMapper;

    /**
     * 查询活动风采浏览记录
     *
     * @param id 活动风采浏览记录主键
     * @return 活动风采浏览记录
     */
    @Override
    public AppActivityShowRead selectAppActivityShowReadById(Long id) {
        return appActivityShowReadMapper.selectAppActivityShowReadById(id);
    }

    /**
     * 查询活动风采浏览记录列表
     *
     * @param appActivityShowRead 活动风采浏览记录
     * @return 活动风采浏览记录
     */
    @Override
    public List<AppActivityShowRead> selectAppActivityShowReadList(AppActivityShowRead appActivityShowRead) {
        return appActivityShowReadMapper.selectAppActivityShowReadList(appActivityShowRead);
    }

    /**
     * 新增活动风采浏览记录
     *
     * @param appActivityShowRead 活动风采浏览记录
     * @return 结果
     */
    @Override
    public int insertAppActivityShowRead(AppActivityShowRead appActivityShowRead) {
        return appActivityShowReadMapper.insertAppActivityShowRead(appActivityShowRead);
    }

    /**
     * 插入浏览记录
     *
     * @param userId 用户id
     * @param deptId 部门的id
     * @param showId 文章的id
     */
    @Override
    @Async
    public void setActivityRead(Long userId, Long deptId, Long showId) {
//        AppActivityShowRead read = new AppActivityShowRead();
//        read.setUserId(userId);
//        read.setShowId(showId);
//        List<AppActivityShowRead> reads = appActivityShowReadMapper.selectAppActivityShowReadList(read);
//        if (reads.size() > 0) { //更新
//            AppActivityShowRead update = new AppActivityShowRead();
//            update.setId(reads.get(0).getId());
//            update.setReadTime(DateUtils.getNowDate());
//            this.updateAppActivityShowRead(update);
//        } else {
//            AppActivityShowRead add = new AppActivityShowRead();
//            add.setReadTime(DateUtils.getNowDate());
//            add.setUserId(userId);
//            add.setDeptId(deptId);
//            add.setShowId(showId);
//            this.insertAppActivityShowRead(add);
//        }
    }

    /**
     * 修改活动风采浏览记录
     *
     * @param appActivityShowRead 活动风采浏览记录
     * @return 结果
     */
    @Override
    public int updateAppActivityShowRead(AppActivityShowRead appActivityShowRead) {
        return appActivityShowReadMapper.updateAppActivityShowRead(appActivityShowRead);
    }

    /**
     * 批量删除活动风采浏览记录
     *
     * @param ids 需要删除的活动风采浏览记录主键
     * @return 结果
     */
    @Override
    public int deleteAppActivityShowReadByIds(Long[] ids) {
        return appActivityShowReadMapper.deleteAppActivityShowReadByIds(ids);
    }

    /**
     * 删除活动风采浏览记录信息
     *
     * @param id 活动风采浏览记录主键
     * @return 结果
     */
    @Override
    public int deleteAppActivityShowReadById(Long id) {
        return appActivityShowReadMapper.deleteAppActivityShowReadById(id);
    }
}
